﻿/***********************************************************************
 * <copyright file="UserControlAccountList.cs" company="BUCA JSC">
 * -->    Copyright (C) statement. All right reserved
 * </copyright>
 * 
 * Created:   Bangnc
 * Email:    bangnc@buca.vn
 * Website:
 * Create Date: Tuesday, February 11, 2014
 * Usage: 
 * 
 * RevisionHistory: 
 * Date         Author               Description 
 * 
 * ************************************************************************/

using System;
using System.Collections.Generic;
using System.Drawing;
using WindowsForms.AOnline.Presenter.Dictionary.Account;
using WindowsForms.AOnline.View.Dictionary;
using WindowsForms.AOnline.WindowsForm.BaseUserControls;
using WindowsForms.AOnline.WindowsForm.FormBase.PropertyGrid;


namespace WindowsForms.AOnline.WindowsForm.UserControl.Dictionary
{
    public partial class UserControlAccountList : BaseTreeListUserControl, IAccountsView
    {
        private readonly AccountsPresenter _accountsPresenter;

        /// <summary>
        /// Initializes a new instance of the <see cref="UserControlFixedAssetCategoryList"/> class.
        /// </summary>
        public UserControlAccountList()
        {
            InitializeComponent();
            _accountsPresenter = new AccountsPresenter(this);
        }

        #region IAccountsView Members

        /// <summary>
        /// Sets the accounts.
        /// </summary>
        /// <value>The accounts.</value>
        public IList<Model.BusinessObjects.Dictionary.AccountModel> Accounts
        {
            set
            {
                treeList.DataSource = value;
                ColumnsCollection.Add(new XtraColumn { ColumnName = "AccountCode", ColumnCaption = "Mã tài khoản", ColumnPosition = 1, ColumnVisible = true, ColumnWith = 100 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "UnitId", ColumnCaption = "đơn vị", ColumnPosition = 1, ColumnVisible = false, ColumnWith = 100 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "AccountName", ColumnCaption = "Tên tài khoản", ColumnPosition = 2, ColumnVisible = true, ColumnWith = 300 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "Description", ColumnCaption = "Diễn giải", ColumnPosition = 3, ColumnVisible = true, ColumnWith = 100 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "IsActive", ColumnCaption = "Được sử dụng", ColumnVisible = true, ColumnPosition = 4 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "Grade", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "IsDetail", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "BalanceSide", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "IsCustomer", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "IsVendor", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "IsTax", ColumnVisible = false });             
                ColumnsCollection.Add(new XtraColumn { ColumnName = "IsInventoryItem", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "IsFixedAsset", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "IsSystem", ColumnVisible = false });
            }
        }

        /// <summary>
        /// Loads the data into tree.
        /// </summary>
        protected override void LoadDataIntoTree(int page)
        {
            TotalPage = _accountsPresenter.GetPageSize();
            if (page<= TotalPage) 
            {
                _accountsPresenter.Display(page);
            }
         
        }

        /// <summary>
        /// Deletes the tree.
        /// </summary>
        protected override string DeleteTree()
        {
          return  new AccountPresenter(null).Delete(int.Parse(PrimaryKeyValue));
        }
        #endregion

        // <summary>
        // Handles the NodeCellStyle event of the treeList control.
        // </summary>
        // <param name="sender">The source of the event.</param>
        // <param name="e">The <see cref="DevExpress.XtraTreeList.GetCustomNodeCellStyleEventArgs"/> instance containing the event data.</param>
        private void treeList_NodeCellStyle(object sender, DevExpress.XtraTreeList.GetCustomNodeCellStyleEventArgs e)
        {
            e.Appearance.Font = Convert.ToBoolean(e.Node["IsDetail"])
                                  ? new Font(e.Appearance.Font.FontFamily, e.Appearance.Font.Size, FontStyle.Regular)
                                  : new Font(e.Appearance.Font.FontFamily, e.Appearance.Font.Size, FontStyle.Bold);
        }

       
    }
}
